package com.elm.common;

import lombok.Data;

import java.util.Date;

@Data
public class ApiResponse<T> {
    private boolean success;
    private String code; 
    private T data;
    private String message;

    // 成功响应构造器
    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setSuccess(true);
        response.setCode("200");
        response.setData(data);
        response.setMessage("操作成功");
        return response;
    }

    // 错误响应构造器
    public static <T> ApiResponse<T> error(String code, String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setSuccess(false);
        response.setCode(code);
        response.setData(null);
        response.setMessage(message);
        return response;
    }

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}